import numpy as np
import pandas as pd
import xml.etree.ElementTree as ET

class XMLDataReader():

    def __init__(self, filename):
        tree = ET.parse(filename)
        root = tree.getroot()
        series_data = []
        for series in root.findall('series'):
            title = series.get('title')
            if title == "dHx1/dx " or title =="d²Hx1/dx² " or title =="dHy1/dx " or title =="d²Hy1/dx² "or title =="dHz1/dx " or title =="d²Hz1/dx² ": # 新增，只处理12道
                print("skip")
                continue
            points = series.findall('points/point')
            data = [] 
            x_none = 0.0
            for point in points:
                index = point.get('Index')
                x = point.get('X')
                y = point.get('Y')
                if x is None:
                    x_none += 8.0
                    x = x_none
                index = int(index.replace(',', ''))
                x = str(x)
                x = float(x.replace(',', ''))
                y = float(y.replace(',', ''))
                data.append((index, x, y))
                #另外两种写法                
                #1 data = [(float(point.get('X').replace(',', '')), float(point.get('Y').replace(',', ''))) for point in points]
                #2 data = [(float(point.get('X')), float(point.get('Y'))) for point in points]
            
            series_data.append((title, data))
        self.seriesData = series_data

class ExcelDataReader():

    def __init__(self, filename):
        self.data_raw_inspect = pd.read_excel(filename, header=None).values
        if self.data_raw_inspect is None:
            return
        length = self.data_raw_inspect[:, 1]